package com.example.my.agiftthat.ui.classify.fragment;

import android.content.Context;
import android.os.Bundle;
import android.support.annotation.Nullable;
import android.support.v4.app.Fragment;
import android.util.Log;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.AbsListView;
import android.widget.AdapterView;
import android.widget.ListView;
import android.widget.Toast;

import com.example.my.agiftthat.R;
import com.example.my.agiftthat.ui.classify.adapter.SingleLeftBaseAdapter;
import com.example.my.agiftthat.ui.classify.bean.PositionBean;

import org.greenrobot.eventbus.EventBus;

import java.util.ArrayList;
import java.util.List;

/**
 * Created by My on 2016/12/22.
 */

public class SingleLeftFragment extends Fragment{
    private Context mContext=null;
    private ListView listView_single;
    private String[] arrSingleTitles=null;
    private List<String> mList=new ArrayList<>();
    @Override
    public void onCreate(@Nullable Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        mContext=getActivity();
    }

    @Nullable
    @Override
    public View onCreateView(LayoutInflater inflater, @Nullable ViewGroup container, @Nullable Bundle savedInstanceState) {
        return inflater.inflate(R.layout.singlefragment_left,null);
    }

    @Override
    public void onViewCreated(View view, @Nullable Bundle savedInstanceState) {
        super.onViewCreated(view, savedInstanceState);
        listView_single= (ListView) view.findViewById(R.id.listView_single);
    }

    @Override
    public void onActivityCreated(@Nullable Bundle savedInstanceState) {
        super.onActivityCreated(savedInstanceState);
        arrSingleTitles = getResources().getStringArray(R.array.arrSingleTitles);
        for (int i = 0; i < arrSingleTitles.length; i++) {
            mList.add(arrSingleTitles[i]);
        }
        SingleLeftBaseAdapter adapter=new SingleLeftBaseAdapter(mContext,mList);
        listView_single.setAdapter(adapter);
//        listView_single.setChoiceMode(AbsListView.CHOICE_MODE_SINGLE);
//        listView_single.setOnItemClickListener(new AdapterView.OnItemClickListener() {
//            @Override
//            public void onItemClick(AdapterView<?> parent, View view, int position, long id) {
//                Toast.makeText(mContext, "666666666666666666666-------" + position, Toast.LENGTH_SHORT).show();
//                Bundle bundle = new Bundle();
//                bundle.putInt("position", position);
//                SingleLeftFragment fragment = new SingleLeftFragment();
//                fragment.setArguments(bundle);
//                Log.i("tag", "|||||||||||||||||||||||||||" + position);
//            }
//        });
        listView_single.setChoiceMode(AbsListView.CHOICE_MODE_SINGLE);
        listView_single.setOnItemClickListener(new AdapterView.OnItemClickListener() {
            @Override
            public void onItemClick(AdapterView<?> parent, View view, int position, long id) {
//                position=listView_single.get;
//                Toast.makeText(mContext, "666666666666666666666-------"+position, Toast.LENGTH_SHORT).show();
//
//                SingleLeftFragment fragment=new SingleLeftFragment();
//                Bundle bundle=new Bundle();
//                bundle.putInt("position",9);
//                fragment.setArguments(bundle);


            }
        });
    }
}
